home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Headers / InputSprocket.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  16.7 KB  |  686 lines  |  [TEXT/CWIE]

  1. /*
  2.  
  3. InputSprocket.h  alpha 1
  4. 5/1/96
  5.  
  6. Copyright (c) Apple Computer 1995, 1996 All Rights Reserved
  7. */
  8.  
  9. #ifndef __INPUTSPROCKET__
  10. #define __INPUTSPROCKET__
  11.  
  12. #include <Types.h>
  13. #include <Events.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18.  
  19.  
  20.  
  21. /****** YOU NEED THESE LINES IF YOU DON'T HAVE THE LATEST TYPES.h
  22.  
  23. struct UnsignedWide {
  24.     UInt32                            hi;
  25.     UInt32                            lo;
  26. };
  27.  
  28. typedef UnsignedWide AbsoluteTime;
  29.  
  30. */
  31.  
  32. // ********************* data types *********************
  33. typedef struct ISpDevicePrivate *ISpDeviceReference;
  34. typedef struct ISpElementPrivate *ISpElementReference;
  35. typedef struct ISpElementListPrivate *ISpElementListReference;
  36. typedef OSType ISpDeviceClass;  // general classs of device, example : keyboard, mouse, joystick
  37. typedef OSType ISpDeviceIdentifier;   // a specific device,  example: standard 1-button mouse, 105key ext. kbd.
  38. typedef OSType ISpElementLabel;
  39. typedef OSType ISpElementKind;
  40.  
  41. //*************** resources ****************
  42.  
  43. enum 
  44. {
  45.     kISpSetListResourceType = 'setl',
  46.     kISpSetDataResourceType = 'setd'
  47. };
  48.  
  49. /*
  50.  * ISpDeviceDefinition
  51.  *
  52.  * This structure provides all the available
  53.  * information for an input device within the system
  54.  *
  55.  */
  56.  
  57. typedef struct ISpDeviceDefinition
  58. {
  59.     Str63 deviceName;                // a human readable name of the device
  60.     ISpDeviceClass theDeviceClass;        // general classs of device example : keyboard, mouse, joystick
  61.     ISpDeviceIdentifier theDeviceIdentifier;        // every distinguishable device should have an OSType
  62.     UInt32 permanentID;            // a cross reboot id unique within that deviceType, 0 if not possible
  63.     UInt32 flags;                // some status flags
  64.     UInt32 reserved1;
  65.     UInt32 reserved2;
  66.     UInt32 reserved3;
  67. } ISpDeviceDefinition;
  68.  
  69. enum
  70. {
  71.     kISpDeviceFlag_HandleOwnEmulation = 1
  72. };
  73.  
  74. /*
  75.  * ISpElementEvent, ISpElementEventPtr
  76.  *
  77.  * This is the structure that event data is passed in.
  78.  *
  79.  */
  80.  
  81. typedef struct ISpElementEvent
  82. {
  83.     AbsoluteTime when;                  // this is absolute time on PCI or later, otherwise it is
  84.                                         // 0 for the hi 32 bits and TickCount for the low 32 bits
  85.     ISpElementReference element;            // a reference to the element that generated this event
  86.     UInt32 refCon;                        // for application usage, 0 on the global list
  87.     UInt32 data;                        // the data for this event
  88. } ISpElementEvent, *ISpElementEventPtr;
  89.  
  90. /*
  91.  * ISpElementInfo, ISpElementInfoPtr
  92.  *
  93.  * This is the generic definition of an element.
  94.  * Every element must contain this information.
  95.  *
  96.  */
  97. typedef struct ISpElementInfo
  98. {
  99.     ISpElementLabel theLabel;
  100.     ISpElementKind theKind;
  101.     Str63 theString;
  102.     UInt32 reserved1;
  103.     UInt32 reserved2;
  104. } ISpElementInfo, *ISpElementInfoPtr;
  105.  
  106. typedef struct ISpNeed
  107. {
  108.     Str63 name;
  109.     short iconSuiteResourceId;    // resource id of the icon suite
  110.     ISpElementKind theKind;
  111.     ISpElementLabel theLabel;
  112.     UInt32 flags;
  113.     UInt32 reserved1;
  114.     UInt32 reserved2;
  115.     UInt32 reserved3;
  116. } ISpNeed;
  117.  
  118. typedef enum ISpNeedFlagBits
  119. {
  120.     kISpNeedFlag_NoMultiConfig = 1
  121. } ISpNeedFlagBits;
  122.  
  123. /*
  124.  *
  125.  * These are the current built values for ISpDeviceClass
  126.  *
  127.  */
  128.  
  129. enum
  130. {
  131.     kISpDeviceClass_SpeechRecognition = 'talk',
  132.     kISpDeviceClass_Mouse = 'mous',
  133.     kISpDeviceClass_Keyboard = 'keyd',
  134.     kISpDeviceClass_Joystick = 'joys',
  135.     kISpDeviceClass_Wheel = 'whel',
  136.     kISpDeviceClass_Pedals = 'pedl',
  137.     kISpDeviceClass_Levers = 'levr'
  138. };
  139.  
  140. /*
  141.  * These are the current built in ISpElementKind's
  142.  * 
  143.  * These are all OSTypes.
  144.  *
  145.  */
  146.  
  147. enum
  148. {
  149.     kISpElementKind_Button = 'butn',
  150.     kISpElementKind_DPad = 'dpad',
  151.     kISpElementKind_Axis = 'axis',
  152.     kISpElementKind_Movement = 'move',
  153.     kISpElementKind_Virtual = 'virt'
  154. };
  155.  
  156.  
  157. /*
  158.  *
  159.  * These are the current built in ISpElementLabel's
  160.  *
  161.  * These are all OSTypes.
  162.  *
  163.  */
  164.  
  165. enum
  166. {
  167.     // generic
  168.     kISpElementLabel_None = 'none',
  169.     
  170.     // axis
  171.     kISpElementLabel_XAxis = 'xaxi',
  172.     kISpElementLabel_YAxis = 'yaxi',
  173.     kISpElementLabel_ZAxis = 'zaxi',
  174.     
  175.     kISpElementLabel_Rx = 'rxax',
  176.     kISpElementLabel_Ry = 'ryax',
  177.     kISpElementLabel_Rz = 'rzax',
  178.     
  179.     kISpElementLabel_Gas = 'gasp',
  180.     kISpElementLabel_Brake = 'brak',
  181.     kISpElementLabel_Clutch = 'cltc',
  182.     
  183.     kISpElementLabel_Throttle = 'thrt',
  184.     kISpElementLabel_Trim = 'trim',
  185.     
  186.     // direction pad
  187.     kISpElementLabel_POVHat = 'povh',
  188.     kISpElementLabel_PadMove = 'move',
  189.     
  190.     // buttons
  191.     kISpElementLabel_Fire = 'fire',
  192.     kISpElementLabel_Start = 'strt',
  193.     kISpElementLabel_Select = 'optn'
  194. };
  195.  
  196. /*
  197.  *
  198.  * direction pad data & configuration information
  199.  *
  200.  */
  201.  
  202. typedef enum ISpDPadData
  203. {
  204.     kISpPadIdle = 0,
  205.     kISpPadLeft,
  206.     kISpPadUpLeft,
  207.     kISpPadUp,
  208.     kISpPadUpRight,
  209.     kISpPadRight,
  210.     kISpPadDownRight,
  211.     kISpPadDown,
  212.     kISpPadDownLeft
  213. } ISpDPadData;
  214.  
  215. typedef struct ISpDPadConfigurationInfo
  216. {
  217.     UInt32 id;                // ordering 1..n, 0 = no relavent ordering of direction pads
  218.     Boolean fourWayPad;        // true if this pad can only produce idle + four directions
  219. } ISpDPadConfigurationInfo;
  220.  
  221. /*
  222.  *
  223.  * button data & configuration information
  224.  *
  225.  */
  226.  
  227. typedef enum ISpButtonData
  228. {
  229.     kISpButtonUp = 0,
  230.     kISpButtonDown = 1
  231. } ISpButtonData;
  232.  
  233. typedef struct ISpButtonConfigurationInfo
  234. {
  235.     UInt32 id;                // ordering 1..n, 0 = no relavent ordering of buttons
  236. } ISpButtonConfigurationInfo;
  237.  
  238. /*
  239.  *
  240.  * axis data & configuration information 
  241.  *
  242.  */
  243.  
  244. #define    kISpAxisMinimum  0x00000000U
  245. #define    kISpAxisMiddle   0x7FFFFFFFU
  246. #define    kISpAxisMaximum  0xFFFFFFFFU
  247.  
  248. typedef struct ISpAxisConfigurationInfo
  249. {
  250.     Boolean    symetricAxis;    // axis is symetric, i.e. meaningful 0ish idle at the kISpAxisMiddle position
  251. } ISpAxisConfigurationInfo;
  252.  
  253.  
  254. typedef struct ISpMovementData
  255. {
  256.     UInt32 xAxis;
  257.     UInt32 yAxis;
  258.     UInt32 direction;    // ISpDPadData version of the movement
  259. } ISpMovementData;
  260.  
  261. enum
  262. {
  263.     kISpVirtualElementFlag_UseTempMem = 1
  264. };
  265.  
  266. enum
  267. {
  268.     kISpElementListFlag_UseTempMem = 1
  269. };
  270.  
  271. // ********************* user level functions *********************
  272.  
  273. /********** user interface functions **********/
  274.  
  275.  
  276. NumVersion ISpGetVersion(void);
  277.  
  278. /*
  279.  *
  280.  * ISpElement_NewVirtual(ISpElementReference *outElement);
  281.  *
  282.  */
  283.  
  284. OSStatus ISpElement_NewVirtual(UInt32 dataSize, ISpElementReference *outElement, UInt32 flags);
  285.  
  286. /*
  287.  *
  288.  * ISpElement_NewVirtualFromNeeds(UInt32 count, ISpNeeds *needs, ISpElementReference *outElements);
  289.  *
  290.  */
  291.  
  292. OSStatus ISpElement_NewVirtualFromNeeds(UInt32 count, ISpNeed *needs, ISpElementReference *outElements, UInt32 flags);
  293.  
  294. /*
  295.  *
  296.  * ISpElement_DisposeVirtual(inElement);
  297.  *
  298.  */
  299.  
  300. OSStatus ISpElement_DisposeVirtual(UInt32 count, ISpElementReference *inElements);
  301.  
  302. /*
  303.  * ISpInit
  304.  *
  305.  */
  306.  
  307. OSStatus ISpInit(
  308.     UInt32 count,
  309.     ISpNeed *needs,
  310.     ISpElementReference *inReferences,
  311.     OSType appCreatorCode,
  312.     OSType subCreatorCode,
  313.     UInt32 flags,
  314.     short setListResourceId, 
  315.     UInt32 version);
  316.     
  317.     
  318. /*
  319.  * ISpConfigure
  320.  *
  321.  */
  322.  
  323. typedef Boolean (*ISpEventProcPtr) (EventRecord* inEvent);
  324.  
  325. OSStatus ISpConfigure(ISpEventProcPtr inEventProcPtr);
  326.  
  327. /*
  328.  *
  329.  * ISpStop
  330.  *
  331.  */
  332.  
  333. OSStatus ISpStop(void);
  334.  
  335. /*
  336.  *
  337.  * ISpSuspend, ISpResume
  338.  *
  339.  */
  340.  
  341. OSStatus ISpSuspend(void);
  342. OSStatus ISpResume(void);
  343.  
  344. /*
  345.  * DevicesExtract
  346.  *
  347.  * DevicesExract will extract as many of the devices from a system wide list as possible.  You pass
  348.  * ina pointer to an array of device references and the size of that array in units of sizeof(ISpDeviceReference)
  349.  * It will return how many device references are in the system wide list in the outCount parameter and 
  350.  * it will copy the minimum of that number and the size of the inBufferCount parameter (how big your array was).
  351.  *
  352.  * ByClass and ByIdentifier are the same except that they will only count and copy device references to devices
  353.  * of the specified class or identifier.
  354.  *
  355.  * Return Codes
  356.  * paramErr
  357.  *
  358.  */
  359.  
  360. OSStatus ISpDevices_Extract(UInt32 inBufferCount, UInt32 *outCount, ISpDeviceReference *buffer);
  361. OSStatus ISpDevices_ExtractByClass(ISpDeviceClass theClass, UInt32 inBufferCount, UInt32 *outCount, ISpDeviceReference *buffer);
  362. OSStatus ISpDevices_ExtractByIdentifier(ISpDeviceIdentifier theIdentifier, UInt32 inBufferCount, UInt32 *outCount, ISpDeviceReference *buffer);
  363.  
  364.  
  365. /*
  366.  * DeactivateDevices, ActivateDevices
  367.  *
  368.  * All devices in the sytem start out activate but if for some reason you don't want to get events
  369.  * from some devices then you can use these class to turn on and off getting those events.  The 
  370.  * most likely case is if you would want to get input from the keyboard or mouse as cursor/text style
  371.  * data.
  372.  *
  373.  * Return Codes
  374.  * paramErr
  375.  *
  376.  */
  377.  
  378. OSStatus ISpDevices_Activate(UInt32 inDeviceCount, ISpDeviceReference *inDevicesToActivate);
  379. OSStatus ISpDevices_Deactivate(UInt32 inDeviceCount, ISpDeviceReference *inDevicesToDeactivate);
  380. OSStatus ISpDevice_IsActive(ISpDeviceReference inDevice, Boolean *outIsActive);
  381.  
  382. /*
  383.  * ISpDevice_GetDefinition
  384.  *
  385.  * pass in the device reference, sizeof(ISpDeviceDefinition) and this will 
  386.  * return the device definition struct for that device into the buffer pointed to 
  387.  * by outStruct
  388.  *
  389.  * Return Codes
  390.  * paramErr
  391.  *
  392.  */
  393.  
  394. OSStatus ISpDevice_GetDefinition(const ISpDeviceReference inDevice, UInt32 buflen, ISpDeviceDefinition *outStruct);
  395.  
  396.  
  397. /*
  398.  *
  399.  * ISpDevice_GetElementList
  400.  *
  401.  * pass in the device reference and this will return the element list for that device
  402.  * you are prohibited from modifiying this element list 
  403.  *
  404.  * Return Codes
  405.  * paramErr
  406.  *
  407.  */
  408.  
  409. OSStatus ISpDevice_GetElementList(const ISpDeviceReference inDevice, ISpElementListReference *outElementList);
  410.  
  411. /*
  412.  *
  413.  * takes an ISpElementReference and returns the group that it is in or 0 if there is
  414.  * no group
  415.  *
  416.  * Return Codes
  417.  * paramErr if inElement is 0
  418.  *
  419.  */
  420.  
  421. OSStatus ISpElement_GetGroup(const ISpElementReference inElement, UInt32 *outGroup);
  422.  
  423. /*
  424.  *
  425.  * takes an ISpElementReference and returns the device that the element belongs 
  426.  * to.
  427.  *
  428.  * Return Codes
  429.  * paramErr if inElement is 0 or outDevice is nil
  430.  *
  431.  */
  432.  
  433. OSStatus ISpElement_GetDevice(const ISpElementReference inElement, ISpDeviceReference *outDevice);
  434.         
  435. /*
  436.  *
  437.  * takes an ISpElementReference and gives the ISpElementInfo for that Element.  This is the
  438.  * the set of standard information.  You get ISpElementKind specific information
  439.  * through ISpElement_GetConfigurationInfo.
  440.  *
  441.  * Return Codes
  442.  * paramErr if inElement is 0 or outInfo is nil
  443.  *
  444.  */
  445.  
  446. OSStatus ISpElement_GetInfo(const ISpElementReference inElement, ISpElementInfoPtr outInfo);
  447.         
  448. /*
  449.  *
  450.  *         
  451.  *
  452.  * takes an ISpElementReference and gives the ISpElementKind specific configuration information
  453.  * 
  454.  * if buflen is not long enough to hold the information ISpElement_GetConfigurationInfo will
  455.  * copy buflen bytes of the data into the block of memory pointed to by configInfo and
  456.  * will return something error.
  457.  *
  458.  * Return Codes
  459.  * paramErr if inElement or configInfo is nil
  460.  * something error if buflen is not long enough to hold the information
  461.  *
  462.  */
  463.  
  464. OSStatus ISpElement_GetConfigurationInfo(const ISpElementReference inElement, UInt32 buflen, void *configInfo);
  465.     
  466. /*
  467.  *
  468.  * ISpElement_GetSimpleState
  469.  *
  470.  * Takes an ISpElementReference and returns the current state of that element.  This is a 
  471.  * specialized version of ISpElement_GetComplexState that is only appropriate for elements
  472.  * whose data fits in a signed 32 bit integer.
  473.  *
  474.  *
  475.  *
  476.  * Return Codes
  477.  * paramErr if inElement is 0 or state is nil
  478.  * err1 if the elements data does not fit in a signed 32 bit integer
  479.  *
  480.  */
  481.  
  482. OSStatus ISpElement_GetSimpleState(const ISpElementReference inElement, UInt32 *state);
  483.  
  484. /*
  485.  *
  486.  * ISpElement_GetComplexState
  487.  *
  488.  * Takes an ISpElementReference and returns the current state of that element.  
  489.  * Will copy up to buflen bytes of the current state of the device into
  490.  * state.
  491.  *
  492.  *
  493.  * Return Codes
  494.  * paramErr if inElement is 0 or state is nil
  495.  * err2 if buflen is not large enough to hold all the data
  496.  *
  497.  */
  498.  
  499. OSStatus ISpElement_GetComplexState(const ISpElementReference inElement, UInt32 buflen, void *state);
  500.  
  501.  
  502. /*
  503.  * ISpElement_GetNextEvent
  504.  *
  505.  * changed 3/14/96
  506.  *
  507.  * It takes in an element  reference and the buffer size of the ISpElementEventPtr
  508.  * it will set wasEvent to true if there was an event and false otherwise.  If there
  509.  * was not enough space to fill in the whole event structure that event will be
  510.  * dequed, as much of the event as will fit in the buffer will by copied and
  511.  * ISpElement_GetNextEvent will return an error.
  512.  *
  513.  * Return Codes
  514.  * paramErr
  515.  * somethingErr - buffer to small
  516.  */
  517.  
  518. OSStatus ISpElement_GetNextEvent(ISpElementReference inElement, UInt32 bufSize, ISpElementEventPtr event, Boolean *wasEvent);
  519.  
  520. /*
  521.  *
  522.  * ISpElement_Flush
  523.  *
  524.  * It takes an ISpElementReference and flushes all the events on that element.  All it guaruntees is
  525.  * that any events that made it to this layer before the time of the flush call will be flushed and
  526.  * it will not flush any events that make it to this layer after the time when the call has returned.
  527.  * What happens to events that occur during the flush is undefined.
  528.  *
  529.  *
  530.  * Return Codes
  531.  * paramErr
  532.  *
  533.  */
  534.  
  535. OSStatus ISpElement_Flush(ISpElementReference inElement);
  536.  
  537.  
  538.  
  539. /*
  540.  * ISpElementList_New
  541.  *
  542.  * Creates a new element list and returns it in outElementList.  In count specifies 
  543.  * the number of element references in the list pointed to by inElements.  If inCount
  544.  * is non zero the list is created with inCount elements in at as specified by the 
  545.  * inElements parameter.  Otherwise the list is created empty.
  546.  *
  547.  *
  548.  * Return Codes
  549.  * out of memory - If it failed to allocate the list because it was out of memory
  550.                    it will also set outElementList to 0
  551.  * paramErr if outElementList was nil
  552.  *
  553.  *
  554.  * Special Concerns
  555.  *
  556.  * interrupt unsafe
  557.  *
  558.  */
  559.  
  560. OSStatus ISpElementList_New(UInt32 inCount, ISpElementReference *inElements, ISpElementListReference *outElementList, UInt32 flags);
  561.  
  562. /*
  563.  * ISpElementList_Dispose
  564.  *
  565.  * Deletes an already existing memory list.  
  566.  *
  567.  *
  568.  * Return Codes
  569.  * paramErr if inElementList was 0
  570.  *
  571.  *
  572.  * Special Concerns
  573.  *
  574.  * interrupt unsafe
  575.  *
  576.  */
  577.  
  578. OSStatus ISpElementList_Dispose(ISpElementListReference inElementList);
  579.  
  580. /*
  581.  * ISpGetGlobalElementList
  582.  *
  583.  * returns the global element list
  584.  *
  585.  * Return Codes
  586.  * paramErr if outElementList is nil
  587.  *
  588.  */ 
  589.  
  590. OSStatus ISpGetGlobalElementList(ISpElementListReference *outElementList);
  591.  
  592. /*
  593.  * ISpElementList_AddElement
  594.  *
  595.  * adds an element to the element list
  596.  *
  597.  * Return Codes
  598.  * paramErr if inElementList is 0 or newElement is 0
  599.  * memory error if the system is unable to allocate enough memory
  600.  *
  601.  * Special Concerns
  602.  * interrupt Unsafe
  603.  * 
  604.  */
  605. OSStatus ISpElementList_AddElements(ISpElementListReference inElementList, UInt32 refCon, UInt32 count, ISpElementReference *newElements);
  606.  
  607. /*
  608.  * ISpElementList_RemoveElement
  609.  *
  610.  * removes the specified element from the element list
  611.  *
  612.  * Return Codes
  613.  * paramErr if inElementList is 0 or oldElement is 0
  614.  * memory error if the system is unable to allocate enough memory
  615.  *
  616.  * Special Concerns
  617.  * interrupt Unsafe
  618.  * 
  619.  */
  620.  
  621. OSStatus ISpElementList_RemoveElements(ISpElementListReference inElementList, UInt32 count, ISpElementReference *oldElement);
  622.  
  623. /*
  624.  * ISpElementList_Extract
  625.  *
  626.  * ISpElementList_Extract will extract as many of the elements from an element list as possible.  You pass
  627.  * in an element list, a pointer to an array of element references and the number of elements in that array.
  628.  * It will return how many items are in the element list in the outCount parameter and copy the minimum of 
  629.  * that number and the size of the array into the buffer.
  630.  *
  631.  * ByKind and ByLabel are the same except that they will only count and copy element references to elements
  632.  * that have the specified kind and label.
  633.  *
  634.  * Return Codes
  635.  * paramErr
  636.  *
  637.  */
  638.  
  639. OSStatus ISpElementList_Extract(ISpElementListReference inElementList, UInt32 inBufferCount, UInt32 *outCount, ISpElementReference *buffer);
  640. OSStatus ISpElementList_ExtractByKind(ISpElementListReference inElementList, ISpElementKind theKind, UInt32 inBufferCount, UInt32 *outCount, ISpElementReference *buffer);
  641. OSStatus ISpElementList_ExtractByLabel(ISpElementListReference inElementList, ISpElementLabel theLabel, UInt32 inBufferCount, UInt32 *outCount, ISpElementReference *buffer);
  642.  
  643. /*
  644.  * ISpElementList_GetNextEvent
  645.  *
  646.  * changed 3/14/96
  647.  *
  648.  * It takes in an element list reference and the buffer size of the ISpElementEventPtr
  649.  * it will set wasEvent to true if there was an event and false otherwise.  If there
  650.  * was not enough space to fill in the whole event structure that event will be
  651.  * dequed, as much of the event as will fit in the buffer will by copied and
  652.  * ISpElementList_GetNextEvent will return an error.
  653.  *
  654.  * Return Codes
  655.  * paramErr
  656.  * somethingErr - buffer to small
  657.  */
  658.  
  659. OSStatus ISpElementList_GetNextEvent(ISpElementListReference inElementList, UInt32 bufSize, ISpElementEventPtr event, Boolean *wasEvent);
  660.  
  661. /*
  662.  *
  663.  * ISpElementList_Flush
  664.  *
  665.  * It takes an ISpElementListReference and flushes all the events on that list.  All it guaruntees is
  666.  * that any events that made it to this layer before the time of the flush call will be flushed and
  667.  * it will not flush any events that make it to this layer after the time when the call has returned.
  668.  * What happens to events that occur during the flush is undefined.
  669.  *
  670.  *
  671.  * Return Codes
  672.  * paramErr
  673.  *
  674.  */
  675.  
  676. OSStatus ISpElementList_Flush(ISpElementListReference inElementList);
  677.  
  678.  
  679.  
  680.  
  681. #ifdef __cplusplus
  682. }
  683. #endif
  684.  
  685. #endif // __INPUTSPROCKET__
  686.